using Microsoft.Extensions.DependencyInjection;
using StockTrading.View.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace StockTrading.ViewModel
{
    public class MainViewModel:NotificationBase
    {
        public CommandBase SwitchPageCommand { get; set; }
        private Page _CurrentPage;
        private LoginViewModel _LoginUser;

        public LoginViewModel LoginUser
        {
            get { return _LoginUser; }
            set
            {
                this._LoginUser = value;
                this.RaisePropertyChange("LoginUser");
            }
        }
        
        public MainViewModel(LoginViewModel user)
        {
            this.LoginUser = user;
            this.SwitchPageCommand = new CommandBase();
            this.SwitchPageCommand.ExecuteAction = new Action<object>(this.Switch);
            this.SwitchPageCommand.CanExecuteFunc = (p =>
            {
                if (p != null)
                    return true;
                else
                    return false;
            });
            this.CurrentPage = (Page)App.serviceProvider.GetService(Type.GetType("StockTrading.View.Pages.StockDetails"));
        }
        public Page CurrentPage
        {
            get { return _CurrentPage; }
            set
            {
                this._CurrentPage = value;
                this.RaisePropertyChange("CurrentPage");
            }
        }

        private void Switch(object parameter)
        {
            if (parameter == null) return;
            var currentpage = parameter as string;

            this.CurrentPage = (Page)App.serviceProvider.GetService(Type.GetType(currentpage));

        }
        
    }
}
